﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_EditTopHot : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Sharemp3DataContext db = new Sharemp3DataContext();
            TopHotLst.DataSource = db.TopHots;
            TopHotLst.DataValueField = "TopHotID";
            TopHotLst.DataTextField = "TopHotName";
            TopHotLst.DataBind();

            TopHotLst.SelectedIndex = 0;
            TopHotLst_SelectedIndexChanged(this, null);
        }
    }

    protected void TopHotLst_SelectedIndexChanged(object sender, EventArgs e)
    {
        LoadTopHotMusic();
    }

    private void LoadTopHotMusic()
    {
        int tophotid = Convert.ToInt32(TopHotLst.SelectedValue);

        Sharemp3DataContext db = new Sharemp3DataContext();

        var musiclst = (from i in db.TopHotMusics
                        where i.TopHotID == tophotid
                        select new
                        {
                            MusicID = i.MusicID,
                            Title = i.Music.Title,
                            AlbumName = i.Music.Album.AlbumName,
                            ArtistName = i.Music.Album.Artist.ArtistName,
                            Rating = i.Music.Rating,
                            Cover = i.Music.Cover,
                            Date = i.Music.Album.Date,
                            Number = i.number
                        }).OrderBy(i => i.Number);

        grvw_TopHotMusic.DataSource = musiclst;
        grvw_TopHotMusic.DataBind();
    }
    protected void grvw_TopHotMusic_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {        
        grvw_TopHotMusic.PageIndex = e.NewPageIndex;
        LoadTopHotMusic();
    }
}